package com.example.assempro

import android.os.Bundle
import android.util.Log
import com.example.a_lib.BizApplication
import com.example.a_lib.SmartObserver
import com.example.a_lib.http.NetHelper
import com.example.a_lib.http.exception.RespException
import com.example.assempro.api.LoginApiService
import com.example.assempro.databinding.ActivityMainBinding
import com.trello.rxlifecycle3.android.ActivityEvent
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity
import com.uber.autodispose.AutoDispose
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.example.a_lib.http.RespHandler
import com.example.a_lib.http.resp.Response
import com.example.assempro.api.LoginApi
import com.example.assempro.api.LoginApi2
import com.example.assempro.model.HomepageIndexInfo
import com.example.assempro.model.User
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class MainActivity : RxAppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.btn.setOnClickListener {


            NetHelper.getInstance().getMyApi(LoginApi2::class.java)
                .getmomentRollnews()
                .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this)))
                .subscribe(object : SmartObserver<HomepageIndexInfo>() {
                    override fun onSuccess(bean: Response<HomepageIndexInfo>?) {
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                        Log.e("tag", "onError: ")
                    }

                })

//            LoginApiService.getInstance(this).login1("a", "")
//                .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this)))
//                .subscribe(object : RespHandler<User>() {
//                    override fun onSuccess(data: User) {
//                        super.onSuccess(data)
//
//                    }
//
//                    override fun onFailure(e: RespException) {
//                        super.onFailure(e)
//
//
//                    }
//
//                })
        }
    }

}